<?php
require_once 'CMS/Util.php';
require_once 'CMS/Mvc/BaseController.php';
require_once 'CMS/Mvc/BaseUserController.php';
require_once 'CMS/UserCommon.php';
require_once 'CMS/User.php';
require_once 'CMS/Language.php'; //include thu vien language


 
class CartSidebar_IndexController{

	public function init(){
		parent::init();
	}

	//Action index thục hiện chức năng show thông tin của module
	public function indexAction(){
	
		/*========== Start Load Language ==========*/
		$language = new Language(APPLICATION_PATH . '/widgets/cartsidebar');
		if(isset($_SESSION['language']))
		{
			$language_id = $_SESSION['language'];
			$tbLanguage = new Language_Model_Language();
			$name = $tbLanguage->getNameLanguage($language_id);
			$language->load($name['name']);
		}
		else
			$language->load('Default');		
		/*========== End Load Language ==========*/
		
		
		/*========== Start Get Text ==============*/
		$this->view->textYourCart 		= $language->get('text_yourcart');
		$this->view->textThereAre 		= $language->get('text_thereare');
		$this->view->textInYourCart 		= $language->get('text_inyourcart');
		$this->view->textCartSubtotal 		= $language->get('text_cartsubtotal');
		$this->view->textRecentlyAdd 		= $language->get('text_recentlyadditems');
		$this->view->textItems 		= $language->get('text_items');
		$this->view->textEmpty 		= $language->get('text_empty');
		$this->view->textCheckout 	= $language->get('text_checkout');
		/*========== End Text ==============*/
		
		//-----------------------Khai báo các parameter----------------------
		$tbThings= new CartSidebar_Model_Things();
		$path = APPLICATION_PATH."/widgets/cartsidebar/";
		$xmlconfig = new SimpleXMLElement($path."config.xml",null,true);//Read config.xml
		//---------------------- Khai báo các parameter----------------------//
		if(isset($_SESSION["Cart"]))
		{
			reset($_SESSION["Cart"]);
			while(list($product, $quan) = each($_SESSION["Cart"]))
				{
				$ProductDetail = $tbThings->getThingById($product);
				if(count($ProductDetail)>0)
					{
					$product_list[count($product_list)]=$ProductDetail[0];
					$product_price[count($product_price)]=$quan;
					}
				}
			if(count($product_list)>0)
			{
			$this->view->product_list = $product_list;
			$this->view->product_price = $product_price;
			}
		}
		//Start------Truyền parameter qua View
		$titleXML = 'title'.$name['name'];
        if(isset($xmlconfig->$titleXML))
        	$this->view->title = $xmlconfig->$titleXML;
        else
        	$this->view->title = $xmlconfig->titleDefault;
		/************ Start check user login *********/
		$session1 = new Zend_Session_Namespace('login.auth');
		if(isset($session1->id_user))
		{
			$this->view->login = "1";
		
			/************ Start check permission *********/
			$user = new User();
			$user->init();
			$hasmodify = $user->modifiy_widget($xmlconfig->name);
			$this->view->permission = $hasmodify;
			/************ End check user permission *********/
		}
		else 
		{
			
			$this->view->login = "0";
		}
		/************ End check user login *********/
		//End------Truyền parameter qua View
	}
	
}